﻿Public Class boxNewestProduct
    Inherits System.Web.UI.UserControl

    Public ConnectionString As String = ConfigurationManager.AppSettings("ConnectionString").ToString
    Public objDataRead As New DatabaseClass(ConnectionString)
    Public objFunction As New FunctionClass
    Public objConfig As New Configs
    Public objAlert As New AlertClass
    Public sql As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            '@SubCatID int,
            '@Type int,
            '@currPage int,
            '@recodperpage int
            Sql = "spo_ProductGetTopNewest "
            Sql &= objFunction.ValueCheck(6)
            ' SQL trên return lại 3 result set theo thứ tự: 0-Danh sách tin, 1-Tổng số tin, 2-Tên category
            Dim dts As DataSet = objDataRead.ExeDataset(Sql)
            ' Đưa dữ liệu của bảng 0 vào Repeater
            RptNewestPro.DataSource = dts.Tables(0)
            RptNewestPro.DataBind()
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub

    ' Build link đến chi tiết sản phẩm dựa trên tên danh mục, tên sp, id sp
    Public Function buildLinkDetailPro(ByVal proId As String) As String
        'Return "/tin-tuc/" & cateName & "/" & proName & "-" & proId
        Return "/ProductDetail.aspx?idPro=" & proId
    End Function

    ' Build src image
    Public Function buildImage(ByVal strDate As String, ByVal strImage As String) As String
        Return objFunction.buildImageByDate(strDate, strImage)
    End Function

    ' format phan Gioi thieu tin, giới hạn 200 ký tự
    Public Function getDesc(ByVal strTmp As String, ByVal limit As Integer) As String
        Return objFunction.CutStringByInterger(strTmp, limit)
    End Function

End Class